package nine.bridge.example;

public class StringDisplayImpl extends DisplayImpl{
    private String string;//要显示的字符串
    private int width;//以字节单位计算出的字符串的宽度

    public StringDisplayImpl(String string) { //构造函数接收要显示的字符串string
        this.string = string;
        this.width = string.getBytes().length;
    }

    @Override
    public void rawOpen() {
        printLine();
    }

    @Override
    public void rawPrint() {
        System.out.println("|" + string + "|");
    }

    @Override
    public void rawClose() {
        printLine();
    }
    private void printLine(){
        System.out.print("+");
        for(int i=0;i<width;i++){
            System.out.print("-");
        }
        System.out.println("+");
    }
}
